package com.linq.cool.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.linq.cool.api.domain.SysOperateLog;
import com.linq.cool.system.dto.SysOperateLogQueryDTO;
import com.linq.cool.system.mapper.SysOperateLogMapper;
import com.linq.cool.system.service.SysOperateLogService;
import com.linq.cool.system.vo.SysOperateLogVO;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: yqlin
 * @Date: 2020/12/29 19:17
 * @Description:
 * @Version: 1.0.0
 */
@Service
public class SysOperateLogServiceImpl extends ServiceImpl<SysOperateLogMapper, SysOperateLog> implements SysOperateLogService {

    @Override
    public IPage<SysOperateLogVO> listByPage(IPage<SysOperateLogVO> page, SysOperateLogQueryDTO dto) {
        return baseMapper.listByPage(page, dto);
    }


    @Override
    public List<SysOperateLog> listByParams(SysOperateLog sysOperateLog) {
        return this.list(this.getLambdaQueryWrapper(sysOperateLog));
    }

    @Override
    public void clean() {
        baseMapper.clean();
    }


    LambdaQueryWrapper<SysOperateLog> getLambdaQueryWrapper(SysOperateLog sysOperateLog) {
        return new LambdaQueryWrapper<SysOperateLog>().eq(StringUtils.checkValNotNull(sysOperateLog.getModuleTitle()), SysOperateLog::getModuleTitle, sysOperateLog.getModuleTitle())
                .eq(StringUtils.checkValNotNull(sysOperateLog.getBusinessType()), SysOperateLog::getBusinessType, sysOperateLog.getBusinessType())
                .eq(StringUtils.checkValNotNull(sysOperateLog.getRequestMethod()), SysOperateLog::getRequestMethod, sysOperateLog.getRequestMethod())
                .eq(StringUtils.checkValNotNull(sysOperateLog.getOperatorType()), SysOperateLog::getOperatorType, sysOperateLog.getOperatorType())
                .like(StringUtils.checkValNotNull(sysOperateLog.getDeptName()), SysOperateLog::getDeptName, sysOperateLog.getDeptName())
                .like(StringUtils.checkValNotNull(sysOperateLog.getIp()), SysOperateLog::getIp, sysOperateLog.getIp())
                .like(StringUtils.checkValNotNull(sysOperateLog.getLocation()), SysOperateLog::getLocation, sysOperateLog.getLocation())
                .eq(StringUtils.checkValNotNull(sysOperateLog.getStatus()), SysOperateLog::getStatus, sysOperateLog.getStatus());
    }
}


